#pragma once
#include <fstream>
#include <string>

#pragma warning( disable : 4996 )

namespace Ymsf {
	namespace Infras {

		#define YM_DEBUG(format)\
			YMLogger::Instance()->Logger(YMLogger::DEBUG, __FILE__, __LINE__, format);

		#define YM_INFO(format)\
			YMLogger::Instance()->Logger(YMLogger::INFO, __FILE__, __LINE__, format);

		#define YM_WARN(format)\
			YMLogger::Instance()->Logger(YMLogger::WARN, __FILE__, __LINE__, format);

		#define YM_ERROR(format)\
			YMLogger::Instance()->Logger(YMLogger::ERROR, __FILE__, __LINE__, format);

		#define YM_FATAL(format)\
			YMLogger::Instance()->Logger(YMLogger::FATAL, __FILE__, __LINE__, format);


		class  __declspec(dllexport) YMLogger
		{
		public:
			static YMLogger* Instance();

			enum Level {
				DEBUG = 0,
				INFO,
				WARN,
				ERROR,
				FATAL,
				LEVLE_COUNT
			};

			void Logger(Level, std::string file, int line, std::string format);

			void Open();
			void Close();
			void SetLevel(Level);
			void SetMax(int);

		private:
			YMLogger();
			~YMLogger();

			void rotate();

		private:
			std::string m_sFileName;
			std::ofstream m_Fout;
			Level m_Level;
			int m_Max;
			int m_Size;
			static const std::string s_Level[LEVLE_COUNT];			
		};



	}
}





